package com.learn.metrics.util;

import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.MetricRegistry;
import lombok.experimental.UtilityClass;

import java.util.concurrent.TimeUnit;

/**
 * @author XuYang
 * @since 2025/2/18 21:57
 */
@UtilityClass
public class MetricUtil {
    public MetricRegistry REGISTRY = new MetricRegistry();

    public void startReporter() {
        startReporter(5);
    }

    public void startReporter(int interval) {
        // 注册到控制台中
        ConsoleReporter reporter = ConsoleReporter.forRegistry(REGISTRY).build();
        // 每5秒输出一次结果
        reporter.start(interval, TimeUnit.SECONDS);
    }
}
